package com.nbjtjc.safe.service.sys;

import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.sys.SysDutyTypeMapper;
import com.nbjtjc.safe.model.sys.SysDutyType;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/8/21 15:54
 **/
@Service
public class SysDutyTypeService {
    @Autowired
    private SysDutyTypeMapper sysDutyTypeMapper;


    public List<SysDutyType> find(SysDutyType sysDutyType){

        List<SysDutyType> sysDutyTypes= sysDutyTypeMapper.selectAll();
        return sysDutyTypes;
    }

    public Result add(SysDutyType sysDutyType){
        Result result=new Result();
        int count=sysDutyTypeMapper.typeCodeCount(sysDutyType.getCodeNum());
        if(count>0){
            result.setFalse("节假日编码重复");
            return result;
        }
        sysDutyTypeMapper.insert(sysDutyType);
        return result;
    }

    public void delete(SysDutyType sysDutyType){
        sysDutyTypeMapper.deleteByPrimaryKey(sysDutyType);
    }

    public SysDutyType update(SysDutyType sysDutyType){
        sysDutyTypeMapper.updateByPrimaryKeySelective(sysDutyType);
        return sysDutyType;
    }

}
